package com.gitee.qdbp.general.thirdpart.biz.alipay.model;

import java.util.Properties;
import com.alipay.api.AlipayConstants;
import com.gitee.qdbp.general.thirdpart.api.alipay.model.IAlipayConfig;
import com.gitee.qdbp.tools.utils.Config;

/**
 * 支付宝交易接口配置项<br>
 * <pre>
    ###### https://docs.open.alipay.com/203/107090/
    ###### 电脑网站支付
    ## 应用ID, 收款账号就是此APPID对应的支付宝账号
    alipay.pagepay.app_id = 2014072300007148
    ## 商户私钥, PKCS8格式RSA2私钥
    alipay.pagepay.merchant_private_key = 
    ## APPID对应的支付宝公钥
    alipay.pagepay.alipay_public_key = 
    ###### 手机网站支付
    ## 应用ID,您的APPID，收款账号既是您的APPID对应支付宝账号
    alipay.wappay.app_id = 2014072300007148
    ## 商户私钥，您的PKCS8格式RSA2私钥
    alipay.wappay.merchant_private_key = 
    ## 支付宝公钥,查看地址：https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
    alipay.wappay.alipay_public_key = 
    ###### 公共参数
    ## 服务器异步通知页面路径: 需http://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问
    alipay.merchant.notify_url = {config:site.manager.outer.url}actions/alipay/notify/
    ## 签名方式
    # alipay.sign_type = RSA2
    ## 支付宝网关
    # alipay.gateway_url =  https://openapi.alipay.com/gateway.do
 *  </pre>
 */
public class AlipayConfig implements IAlipayConfig {

    private Config config;

    public AlipayConfig(Properties properties) {
        this.config = new Config(properties);
    }

    @Override
    public boolean isPaymentTest() {
        return "true".equalsIgnoreCase(config.getString("payment.test", false));
    }

    public String getAlipayGatewayUrl() {
        return config.getStringUseDefValue("alipay.gateway_url", "https://openapi.alipay.com/gateway.do");
    }

    public String getDataFormat() {
        return config.getStringUseDefValue("alipay.data_format", AlipayConstants.FORMAT_JSON);
    }

    public String getSignType() {
        return config.getStringUseDefValue("alipay.sign_type", AlipayConstants.SIGN_TYPE_RSA2);
    }

    public String getEncryptType() {
        return config.getStringUseDefValue("alipay.encrypt_type", AlipayConstants.ENCRYPT_TYPE_AES);
    }

    public String getCharset() {
        return config.getStringUseDefValue("alipay.encrypt_type", AlipayConstants.CHARSET_UTF8);
    }

    @Override
    public String getPaymentUrlPrefix() {
        return config.getString("payment.url.prefix", false);
    }

    public String getMerchantNotifyUrl() {
        return config.getString("alipay.merchant.notify_url");
    }

    public String getDefaultAppId() {
        return config.getString("alipay.app_id");
    }

    public String getDefaultMerchantPrivateKey() {
        return config.getString("alipay.merchant_private_key");
    }

    public String getDefaultAlipayPublicKey() {
        return config.getString("alipay.alipay_public_key");
    }

    public String getDefaultEncryptKey() {
        return config.getString("alipay.encrypt_key");
    }

    /** PC网页支付AppId **/
    public String getPagePayAppId() {
        return config.getStringUseDefValue("alipay.pagepay.app_id", getDefaultAppId());
    }

    /** PC网页支付MerchantPrivateKey **/
    public String getPagePayMerchantPrivateKey() {
        return config.getStringUseDefValue("alipay.pagepay.merchant_private_key", getDefaultMerchantPrivateKey());
    }

    /** PC网页支付AlipayPublicKey **/
    public String getPagePayAlipayPublicKey() {
        return config.getStringUseDefValue("alipay.pagepay.alipay_public_key", getDefaultAlipayPublicKey());
    }

    /** PC网页支付EncryptKey **/
    public String getPagePayEncryptKey() {
        return config.getStringUseDefValue("alipay.pagepay.encrypt_key", getDefaultEncryptKey());
    }

    /** 手机网页支付AppId **/
    public String getWapPayAppId() {
        return config.getStringUseDefValue("alipay.wappay.app_id", getDefaultAppId());
    }

    /** 手机网页支付MerchantPrivateKey **/
    public String getWapPayMerchantPrivateKey() {
        return config.getStringUseDefValue("alipay.wappay.merchant_private_key", getDefaultMerchantPrivateKey());
    }

    /** 手机网页支付AlipayPublicKey **/
    public String getWapPayAlipayPublicKey() {
        return config.getStringUseDefValue("alipay.wappay.alipay_public_key", getDefaultAlipayPublicKey());
    }

    /** 手机网页支付EncryptKey **/
    public String getWapPayEncryptKey() {
        return config.getStringUseDefValue("alipay.wappay.encrypt_key", getDefaultEncryptKey());
    }
}
